package pers.mine.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import pers.mine.vo.Info;

/**
 * Admin用户权限拦截器
 * 
 * @author Mine
 * @since 2016年10月26日_下午10:43:55
 */
public class AdminInterceptor implements HandlerInterceptor {
	private Info logininfo = new Info();// 放到首页的信息
	double x=12E1;
	
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		// 尝试获取session中的admin
		if (request.getSession().getAttribute("admin") == null) {
			logininfo.setType(Info.ERROR);
			logininfo.setMsg("[Admin拦截器信息]:管理员未登录,请先登录...");
			request.setAttribute("logininfo", logininfo);
			System.out.println("[Admin未登录,已拦截...]");
			request.getRequestDispatcher("/WEB-INF/views/adminLogin.jsp")
					.forward(request, response);
			return false;
		}
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO 自动生成的方法存根

	}

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO 自动生成的方法存根

	}

}
